export function getDate() {
    return new Date();
};

export function getDateDiff(time1, time2) {
    time1 = new Date(time1).valueOf();
    time2 = new Date(time2).valueOf();
    var sub = time1 - time2;

    var d = 24 * 60 * 60 * 1000;
    var h = 60 * 60 * 1000;
    var m = 60 * 1000;
    var s = 1000;

    var days = ~~(sub / d);
    sub -= days * d;
    var hours = ~~(sub / h);
    sub -= hours * h;
    var mins = ~~(sub / m);
    sub -= mins * m;
    var seds = ~~(sub / s);
    sub -= seds * s;

    return {
        days,
        hours,
        mins,
        seds,
        ms: sub
    }
};

export function zeroize(str, fix) {
    if (isNaN(Number(fix))) return str;
    return String(str).padStart(fix, "0");
    // str = String(str);
    // if (str.length >= fix) return str;
    // var x = "0".repeat(Number(fix)).split("");
    // for (let i in str.split("").reverse()) {
    //     x[x.length - i - 1] = str.split("").reverse()[i];
    // }
    // return x.join("");
};

export function daysCountdownStr(date) {
    var diff = getDateDiff(date, Date.now());
    return `${zeroize(diff.days, 3)}天${zeroize(diff.hours, 2)}时${zeroize(diff.mins, 2)}分${zeroize(diff.seds, 2)}秒`
}
